// pages/Mecollect/Mecollect.js
const {
  request
} = require("../../utils/index.js")
Page({
  /**
   * 页面的初始数据
   */
  data: {
    tabs:[
      {id:1,name:"精英分享",isActive:true},
      {id:2,name:"商业共享",isActive:false},
      {id:3,name:"互助中心",isActive:false},
      {id:4,name:"活动组织",isActive:false},
      {id:5,name:"招聘信息",isActive:false},
    ],
    resultList: [],
    Eliteshare: {
      pageNum: 1, //页码
      pageSize: 10, //条数
      searchName: "",
      isMy:"",
      searchLabel:"collect"
    },
    Eliteshare2: {
      pageNum: 1, //页码
      pageSize: 10, //条数
      isMy:"",
      searchName:"",
      searchLabel:"collect"
    },
    width:"140%"
  },

  //选项卡切换
  handleClickItem(e){
    let {index} = e.detail;
    let {tabs} = this.data;
    tabs.forEach((val,i) => {
      i===index?val.isActive=true:val.isActive=false;
      if(i===index){
        switch(val.id){
          case 1:
            this.shareinit();
            break;
          case 2:
            this.releinit();
            break;
          case 3:
            this.Helpinit();
            break;
          case 4:
            this.calledinit();
            break;
          case 5:
            this.recruinit();
            break;
        }
      }
    });
    
    this.setData({
      tabs
    });
  },
  watch:{
    tabs(val,old){
      console.log(val);
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.shareinit();
  },
  //精英每日分享列表
  async shareinit() {
    try {
      let that = this;
      let par = {
        url: "hw/portal/articles/ds/page?token=" + wx.getStorageSync('token'),
        method: "GET",
        data: that.data.Eliteshare,
        header: {
          "Content-Type": "application/json"
        }
      }
      let datainfo = await request(par);
      if (datainfo.status == 100) {
        that.setData({
          resultList: datainfo.data
        })
      }
    } catch (error) {
      console.log(error);
    }
  },
  //获得商业发布列表数据
  async releinit(){
    try {
      let that = this;
      let par = {
        url: "hw/portal/articles/bw/page?token="+wx.getStorageSync('token'),  
        method: "GET",
        data:that.data.Eliteshare,
        header:{
          "Content-Type":"application/json"
        }
      }
      let datainfo = await request(par);
      if(datainfo.status==100){
        that.setData({
          resultList:datainfo.data
        })
      }
    } catch (error) {
      console.log(error);
    }
  },
  //互助信息列表数据获取
  async Helpinit(){
    try {
      let that = this;
      let par = {
        url: "hw/portal/articles/mi/page?token="+wx.getStorageSync('token'),
        method: "GET",
        data:that.data.Eliteshare,
        header:{
          "Content-Type":"application/json"
        }
      }
      let datainfo = await request(par);
      if(datainfo.status==100){
        that.setData({
          resultList:datainfo.data
        })
        console.log(this.data.resultList)
      }
    } catch (error) {
      console.log(error);
    }
  },
  //获得活动召集列表数据
  async calledinit(){
    try {
      let that = this;
      let param = {
        url:"hw/portal/activity/page?token="+wx.getStorageSync('token'),
        method: "GET",
        data:that.data.Eliteshare2,
        header:{
          "Content-Type":"application/json"
        }
      }
        let datainfo = await request(param);
        console.log(datainfo)
        if(datainfo.status == 100){
          that.setData({
            resultList:datainfo.data
          })
          console.log(this.data.resultList)
        }
    } catch (error) {
      console.log(error)
    }
  },
  //招聘合作数据资料
  async recruinit() {
    try {
      let that = this;
      let par = {
        url: "hw/portal/recruited/page?token=" + wx.getStorageSync('token'),
        method: "GET",
        data: that.data.Eliteshare,
        header: {
          "Content-Type": "application/json"
        }
      }
      let datainfo = await request(par);
      this.setData({
        resultList:datainfo.data
      })
    } catch (error) {
      console.log(error)
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})